package com.itheima.health.controller;

import com.itheima.health.common.MessageConst;
import com.itheima.health.entity.PageResult;
import com.itheima.health.entity.QueryPageBean;
import com.itheima.health.entity.Result;
import com.itheima.health.pojo.Permission;
import com.itheima.health.service.PermissionService;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("permission")
@Slf4j
public class PermissionController {


    @DubboReference
    PermissionService permissionService;

    /**
     * @Author: JASON
     * @Date: 19:34 2021/1/16
     * @Parms [queryPageBean]
     * @ReturnType: com.itheima.health.entity.Result
     * @Description: 权限分页查询
    */
    @GetMapping("findByPage")
    public Result findByPage(QueryPageBean queryPageBean){
      log.info("[权限控制-分页查询]data：{}",queryPageBean);
      PageResult pageResult =permissionService.findByPage(queryPageBean);
      return new Result(true, "查询权限列表成功", pageResult);
    }

    /**
     * @Author: JASON
     * @Date: 20:05 2021/1/16
     * @Parms [id]
     * @ReturnType: com.itheima.health.entity.Result
     * @Description: 根据id查找权限
    */
    @GetMapping("findById")
    public Result findById(Integer id){
        log.info("Controller[权限]根据id查找数据"+id);
        Permission permission=permissionService.findById(id);
        return new Result(true,MessageConst.QUERY_CHECKITEM_SUCCESS,permission);
    }


    @PostMapping("/edit")
    public Result edit(@RequestBody Permission permission){
        log.info("Controller[权限]编辑"+permission);
        permissionService.edit(permission);
        return new Result(true,MessageConst.EDIT_CHECKITEM_SUCCESS);
    }


    @GetMapping("/findAll")
    public Result findAll(){
        log.info("Controller[权限]查询所有");
        List<Permission> list =permissionService.findAll();
        return new Result(true,MessageConst.QUERY_CHECKITEM_SUCCESS,list);
    }


    @PostMapping("/delete")
    public Result delete(Integer id){
        log.info("Controller[检查项]根据id删除数据"+id);
        permissionService.delete(id);
        return new Result(true,MessageConst.DELETE_CHECKITEM_SUCCESS);
    }


    @PostMapping("/add")
    public Result add(@RequestBody Permission permission){
        log.info("Controller[权限]添加数据"+permission);
        permissionService.add(permission);
        return new Result(true,MessageConst.ADD_CHECKITEM_SUCCESS);
    }

}
